package ibm.cognos.imt.template

import groovy.xml.MarkupBuilder

/**
 * Created with IntelliJ IDEA.
 * User: eric
 * Date: 5/9/14
 * Time: 9:19 AM
 * To change this template use File | Settings | File Templates.
 */
class LayoutsTemplate extends AbstractTemplate{

    def elementMap

    LayoutsTemplate(map) {
        elementMap = map
    }

    @Override
    def generateTemplateSpec(MarkupBuilder builder) {
        builder.layouts {
            layout {
                reportPages {
                    page(name: "Page1") {
                        style {
                            defaultStyles {
                                defaultStyle(refStyle: "pg")
                            }
                        }
                        pageBody {
                            style {
                                defaultStyles {
                                    defaultStyle(refStyle: "pb")
                                }
                            }
                            contents()
                        }
                    }
                }
            }
        }
    }

    @Override
    def getTemplateNode() {
        root = new XmlSlurper().parseText(getSpecStr())
        elementMap.each{ k, v ->
            root.layout.reportPages.page.pageBody.contents.appendNode(v.getDomNode())
        }
        root
    }
}
